<html>
<head><meta charset="utf-8"><title>NonZeroLayout: is this too heavyhanded? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html">NonZeroLayout: is this too heavyhanded?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="188665900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188665900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188665900">(Feb 20 2020 at 18:49)</a>:</h4>
<p>Raising requirements to the type level is generally a good thing. But especially given that manual allocation is inherently an <code>unsafe</code> operation, I'm wondering if it's a bit heavy-handed and not really necessary.</p>
<p>Rust does pride itself on zero-cost abstractions and pick-your-costs, but moreso than that, I think Rust also is useful because it is _safe by default_. IOW, the first API you tend to reach for should be the safest to use; for the case of allocators, that would mean requiring them to handle zero-sized allocations transparently, rather than pushing that to the user.</p>
<p>Going through the list of <code>Alloc</code>-friends traits in alloc-wg, per that concept, the available methods that could reasonably need to handle zero-sized "allocations", or can pretend they don't exist would be:</p>
<ul>
<li><code>alloc(Layout)</code></li>
<li><code>alloc_zeroed(Layout)</code></li>
<li><code>dealloc(ptr, Layout)</code></li>
<li><code>realloc(ptr, Layout, Layout)</code></li>
<li><code>grow_in_place(ptr, Layout, usize)</code></li>
<li><code>shrink_in_place(ptr, Layout, usize)</code></li>
</ul>
<p>i.e. all of them could fairly reasonably be expected to work transparently with zero sized allocations.</p>



<a name="188666196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188666196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emil Lauridsen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188666196">(Feb 20 2020 at 18:52)</a>:</h4>
<p>Might've posted this in the wrong stream :)</p>



<a name="188666226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188666226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188666226">(Feb 20 2020 at 18:52)</a>:</h4>
<p>How did this happen :P</p>



<a name="188666263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188666263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188666263">(Feb 20 2020 at 18:52)</a>:</h4>
<p>I am too unfamiliar with Zulip apparently...</p>



<a name="188666379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188666379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188666379">(Feb 20 2020 at 18:54)</a>:</h4>
<p>Really, when my narrow is t-libs/wg-allocators, &lt;kbd&gt;New topic&lt;/kbd&gt; really should default to being in that stream</p>



<a name="188666666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188666666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188666666">(Feb 20 2020 at 18:56)</a>:</h4>
<p>Hi m8, great to see you again!</p>



<a name="188668430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188668430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188668430">(Feb 20 2020 at 19:16)</a>:</h4>
<p>Yeah I don't keep up with Zulip enough</p>



<a name="188691430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188691430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188691430">(Feb 20 2020 at 23:48)</a>:</h4>
<p><span class="user-mention" data-user-id="132829">@Christopher Durham</span> hey, do you want to push for alloc_layout_extras to be stabilized? :D </p>
<p>I am slowly doing that rowan refactoring, and I could use a way to allocate stuff without doing all the layout calculations wrongly myself</p>



<a name="188691505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188691505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188691505">(Feb 20 2020 at 23:49)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> just use <a href="https://github.com/cad97/pointer-utils" target="_blank" title="https://github.com/cad97/pointer-utils">pointer-utils</a> now that it's published :P</p>
<p>But yeah, alloc_layout_extras seems worth to push to stabilize</p>



<a name="188691592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188691592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188691592">(Feb 20 2020 at 23:50)</a>:</h4>
<p>And honestly just give me an actual target of what to do and I'll probably nerd snipe myself into banging it out</p>



<a name="188692454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188692454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188692454">(Feb 21 2020 at 00:03)</a>:</h4>
<p>I sort-of lean towards vendoring the exact combo of union of tagged DST arcs into rowan</p>



<a name="188692484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188692484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188692484">(Feb 21 2020 at 00:03)</a>:</h4>
<p>As we maybe might want to swticht to u32 ref count without weekrefs as well</p>



<a name="188692544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188692544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188692544">(Feb 21 2020 at 00:04)</a>:</h4>
<p>I've started <a href="https://github.com/rust-analyzer/bonsai" target="_blank" title="https://github.com/rust-analyzer/bonsai">https://github.com/rust-analyzer/bonsai</a> a while back, which I think is even sort-of works, except for the bit where I need to cacl the layout :D</p>



<a name="188694078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout%3A%20is%20this%20too%20heavyhanded%3F/near/188694078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christopher Durham <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/NonZeroLayout.3A.20is.20this.20too.20heavyhanded.3F.html#188694078">(Feb 21 2020 at 00:31)</a>:</h4>
<p>I'll take a look at bonsai and push for alloc_layout_extras I guess</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>